package com.pet.platform.controller;

import com.pet.platform.common.PageResult;
import com.pet.platform.common.Result;
import com.pet.platform.dto.PetHealthDTO;
import com.pet.platform.dto.PetHealthQueryDTO;
import com.pet.platform.service.PetHealthService;
import com.pet.platform.util.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/api/pet-health")
@RequiredArgsConstructor
public class PetHealthController {

    private final PetHealthService petHealthService;

    @GetMapping("/{id}")
    public Result<PetHealthDTO> findById(@PathVariable Long id) {
        return Result.success(petHealthService.findById(id));
    }

    @GetMapping("/pet/{petId}")
    public Result<List<PetHealthDTO>> findByPetId(@PathVariable Long petId) {
        return Result.success(petHealthService.findByPetId(petId));
    }

    @GetMapping
    public Result<PageResult<PetHealthDTO>> findPage(PetHealthQueryDTO queryDTO) {
        return Result.success();
//        petHealthService.findPage(queryDTO)
    }

    @PostMapping
    public Result<Void> create(@Valid @RequestBody PetHealthDTO petHealthDTO) {
        petHealthService.create(petHealthDTO);
        return Result.success();
    }

    @PutMapping("/{id}")
    public Result<Void> update(@PathVariable Long id, @Valid @RequestBody PetHealthDTO petHealthDTO) {
        petHealthService.update(id, petHealthDTO);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result<Void> delete(@PathVariable Long id) {
        petHealthService.delete(id);
        return Result.success();
    }

    @PostMapping("/{id}/attachment")
    public Result<String> uploadAttachment(@PathVariable Long id, @RequestParam("file") MultipartFile file) {
        return Result.success();
//        petHealthService.uploadAttachment(id, file)
    }
}